using System.Collections.Generic;
using GameAnalyticsSDK;

namespace Voodoo.Sauce.Internal.Analytics
{
	internal class ProgressEvent : GameAnalyticsEvent
	{
		private readonly GAProgressionStatus _status;

		private readonly string _progress;

		private readonly int? _score;

		private readonly Dictionary<string, object> _customFields;

		protected override void PerformTrackEvent()
		{
			if (_score.HasValue)
			{
				if (_customFields != null)
				{
					GameAnalytics.NewProgressionEvent(_status, _progress, _score.Value, _customFields);
				}
				else
				{
					GameAnalytics.NewProgressionEvent(_status, _progress, _score.Value);
				}
			}
			else if (_customFields != null)
			{
				GameAnalytics.NewProgressionEvent(_status, _progress, _customFields);
			}
			else
			{
				GameAnalytics.NewProgressionEvent(_status, _progress);
			}
		}

		public ProgressEvent(GAProgressionStatus status, string progress, int? score, Dictionary<string, object> customFields)
			: base(status.ToString())
		{
			_status = status;
			_progress = ((!string.IsNullOrEmpty(progress)) ? progress : "0");
			_score = score;
			_customFields = customFields;
		}
	}
}
